home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / newsgroups / misc.19980424-19980901 / 000088_news@newsmaster….columbia.edu _Sun May 17 18:46:02 1998.msg < prev    next >
Internet Message Format  |  1998-08-31  |  3KB

  1. Return-Path: <news@newsmaster.cc.columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.35.30])
  3.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id SAA10625
  4.     for <kermit.misc@watsun.cc.columbia.edu>; Sun, 17 May 1998 18:46:01 -0400 (EDT)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id SAA21694
  7.     for kermit.misc@watsun; Sun, 17 May 1998 18:46:01 -0400 (EDT)
  8. From: heiby_u@falkor.chi.il.us (Ron Heiby)
  9. Subject: CRC-CCITT in C-Kermit?
  10. Date: Sun, 17 May 1998 22:35:52 GMT
  11. Organization: Strategis Consulting Inc.
  12. Message-ID: <355f6176.22879615@149.174.211.108>
  13. X-Newsreader: Forte Agent 1.5/32.451
  14. MIME-Version: 1.0
  15. Content-Type: text/plain; charset=us-ascii
  16. Content-Transfer-Encoding: 7bit
  17. Newsgroups: comp.protocols.kermit.misc
  18. Path: news.columbia.edu!panix!howland.erols.net!ais.net!WCG!arl-news-svc-3.compuserve.com!news-master.compuserve.com!nntp-ntawwabp.compuserve.com
  19. Lines: 48
  20. Xref: news.columbia.edu comp.protocols.kermit.misc:8741
  21.  
  22. Hi! I'm trying to come up with definition and example implementation of
  23. CRC-CCITT for a standards effort I'm involved with.
  24.  
  25. I have run across several implementations that claim to implement CRC-CCITT.
  26.  
  27. One of these provided both table-driven and non-table implementations (that
  28. resulted in the same values for the tests I ran). Then, there's another
  29. table-driven implementation that comes up with a different value, but the
  30. same value as is obtained from the MKS Toolkit's "sum -i" command. These two
  31. table-driven implementations each use a table of 256 16-bit elements that
  32. have different element values.
  33.  
  34. Then, we have the code used by C-Kermit. This code appears to use two tables
  35. of 16 16-bit elements each, quite a few less than the other two table-driven
  36. implementations, but with more computation, though less computation than the
  37. non-table implementation I found. But, this code seems to come up with yet a
  38. third value for my test cases.
  39.  
  40. Then, we have information that was quoted to me from an X.25 spec, that
  41. indicates that the CRC must be pre-loaded with 0xffff and other
  42. complexities, but which never really comes out and gives a step-by-step
  43. procedure that someone who hasn't seen "New Math" in many years could hope
  44. to follow.
  45.  
  46. I'd really appreciate it if someone could give me a hand with this. The
  47. implementations I have from the same person with both table and non-table
  48. versions giving the same result are very attractive, as the receiving side
  49. can clock in the transmitted (LSB, MSB) CRC through the calculation and get
  50. 0x0000 if the frame arrived intact. This seems simpler than cranking octets
  51. through two behind, in case these last two are the CRC, then comparing the
  52. result of the calculation with those last two octets. But, I want to make
  53. sure that what I use will actually work.
  54.  
  55. Here's the non-table code that I'd like to use if I can.
  56.  
  57. unsigned short crcccitt(unsigned short crc, unsigned char c)
  58. {
  59.     unsigned short newcrc;
  60.  
  61.     newcrc = (crc & 0xff) ^ char;
  62.     newcrc = newcrc ^ (newcrc << 4);
  63.     newcrc = (newcrc << 8) ^ (newcrc << 3) ^ (newcrc >> 4) ^ (crc >> 8);
  64.  
  65.     return newcrc;
  66. }
  67.  
  68. Thanks much!
  69.